<template id="entityDialog">
  <div class="content">
    <el-dialog
      :title="options.dialogTitle"
      :visible.sync="options.isShow"
      width="60%"
      :before-close="close"
    >
      <section id="myForm">
        <div class="myForm">
          <div
            class="line"
            v-for="(item, index) in options.myFormList"
            :key="index"
          >
            <div class="topInfo">
              <span class="star" v-if="item.required">*</span>
              <p class="name">{{ item.name }}：</p>
            </div>
            <div class="centerInfo">
              <p class="num" v-if="item.prop == 'phone' || item.prop == 'tel'">
                +86
              </p>
              <input
                :type="item.text == 'number' ? 'number' : 'text'"
                class="content"
                v-model="item.value"
                v-if="item.type == 'input'"
                @blur="trimValue(item)"
                @input="writeValue(item)"
                :placeholder="'请填写' + item.name"
              />
              <div class="areaGroup" v-else></div>
              <transition name="fade">
                <span class="tips" v-if="item.isShowTips">
                  {{ item.tips }}{{ item.name }}
                </span>
              </transition>
            </div>
          </div>
        </div>
      </section>

      <section class="foot">
        <div class="confirmBtn" @click="confirm">保存收获地址</div>
      </section>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {},
  name: "",
  props: {
    options: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  computed: {},
  methods: {
    trimValue(item) {
      let reg = new RegExp();
      if (item.prop == "phone") {
        reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
      } else if (item.prop == "email") {
        reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
      }

      if (item.required && item.value) {
        if (!reg.test(item.value)) {
          this.$emit("tipShow", item, "reg");
          return false;
        } else {
          return true;
        }
      } else if (!item.required && item.value) {
        if (!reg.test(item.value)) {
          this.$emit("tipShow", item, "reg");
          return false;
        } else {
          return true;
        }
      } else if (item.required && !item.value) {
        this.$emit("tipShow", item, "req");
        return false;
      } else {
        return true;
      }
    },
    writeValue(item) {
      this.$emit("tipHiden", item);
    },
    close() {
      this.$emit("close");
    },
    confirm() {
      let res = true;
      this.options.myFormList.map((item, index) => {
        if (!this.trimValue(item)) {
          res = false;
        }
      });
      if (res) {
        this.$emit("confirm");
      }
    },
  },
  mounted() {},
};
</script>

<style lang="less" scoped>
.content {
  font-family: PingFangSC-Semibold, PingFang SC;
  p {
    margin: 0;
  }
  /deep/.el-dialog__header {
    display: block !important;
    border-bottom: 1px solid #fff;
    .el-dialog__title {
      color: #fff;
    }
  }
  /deep/.el-dialog__body {
    height: auto !important;
    padding: 40px !important;
  }
  /deep/.el-dialog {
    width: 900px !important;
    // height: 480px;
    background: #1e2020;
    border-radius: 5px;
  }
  .myForm {
    width: 100%;
    margin-bottom: 40px;
    .line {
      margin-bottom: 30px;
      position: relative;
      .topInfo {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
        .star {
          color: #f34c44;
          margin-right: 3px;
        }
        .name {
          color: #fff;
          font-size: 14px;
          min-width: 120px;
          word-break: keep-all;
        }
      }
      .centerInfo {
        display: flex;
        align-items: center;
        .num {
          word-break: keep-all;
          padding: 0 5px;
          background: #292b2b;
          height: 40px;
          display: flex;
          align-items: center;
        }
        .content {
          border: none;
          width: 100%;
          height: 40px;
          background: #292b2b;
          border-radius: 4px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #ffffff;
          line-height: 30px;
          padding: 0 12px;
        }
        input::-webkit-input-placeholder {
          /* WebKit browsers 适配谷歌 */
          color: rgba(255, 255, 255, 0.5) !important;
        }

        input:-moz-placeholder {
          /* Mozilla Firefox 4 to 18 适配火狐 */
          color: rgba(255, 255, 255, 0.5) !important;
        }

        input::-moz-placeholder {
          /* Mozilla Firefox 19+ 适配火狐 */
          color: rgba(255, 255, 255, 0.5) !important;
        }

        input:-ms-input-placeholder {
          /* Internet Explorer 10+  适配ie*/
          color: rgba(255, 255, 255, 0.5) !important;
        }
        .tips {
          position: absolute;
          left: 0;
          bottom: -22px;
          color: #f34c44;
        }
        .fade-enter-active,
        .fade-leave-active {
          transition: all 0.4s;
          transform: translateY(-0px);
        }

        .fade-enter,
        .fade-leave-active {
          opacity: 0;
          transform: translateY(-5px);
        }
      }
    }
    .line:nth-child(4),
    .line:nth-child(5) {
      .content {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
      }
    }
  }
  .foot {
    display: flex;
    justify-content: end;
    .confirmBtn {
      display: flex;
      align-items: center;
      justify-content: center;
      border: none;
      background: none;
      width: 215px;
      height: 39px;
      background-image: url("../../../assets/images/pc_black/home/btn_color.png");
      background-position: center center;
      background-size: 100% 100%;
      font-size: 14px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #1e2020;
      line-height: 14px;
      cursor: pointer;
    }
  }
}
</style>
